<?php

namespace App\Admin\Forms;

use Dcat\Admin\Widgets\Form;

class YpayForm extends Form
{
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        // dump($input);
        admin_setting($input);
        // return $this->response()->error('Your error message.');

        return $this
				->response()
				->success('保存成功')
				->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->text('ypay_id','易支付ID')->default(admin_setting('ypay_id', '1000'))->required();
        $this->text('ypay_key','易支付KEY')->default(admin_setting('ypay_key', '123456'))->required();
        $this->text('ypay_url','易支付接口')->default(admin_setting('ypay_url', 'https://www.mengyunblog.com'))->required();

        // 新增支付通道开关
        $this->switch('ypay_qq_enable', 'QQ支付')->default(admin_setting('ypay_qq_enable', 0))->options([
            'on'  => ['value' => 1, 'text' => '开启'],
            'off' => ['value' => 0, 'text' => '关闭'],
        ]);
        $this->switch('ypay_wechat_enable', '微信支付')->default(admin_setting('ypay_wechat_enable', 0))->options([
            'on'  => ['value' => 1, 'text' => '开启'],
            'off' => ['value' => 0, 'text' => '关闭'],
        ]);
        $this->switch('ypay_alipay_enable', '支付宝支付')->default(admin_setting('ypay_alipay_enable', 0))->options([
            'on'  => ['value' => 1, 'text' => '开启'],
            'off' => ['value' => 0, 'text' => '关闭'],
        ]);
    }
    /**
     * The data of the form.
     *
     * @return array
     */

     public function default()
    {
        return [
            'recharge'  => admin_setting('recharge'),
            // 添加支付通道默认值
            'ypay_qq_enable' => admin_setting('ypay_qq_enable', 0),
            'ypay_wechat_enable' => admin_setting('ypay_wechat_enable', 0),
            'ypay_alipay_enable' => admin_setting('ypay_alipay_enable', 0)
        ];
    }
}
